package ecstore.client.customWidgets;

import com.google.gwt.user.client.ui.Composite;
import com.google.gwt.user.client.ui.VerticalPanel;
import com.google.gwt.user.client.ui.DecoratorPanel;
import com.google.gwt.user.client.ui.Image;
import com.google.gwt.user.client.ui.Label;
import com.google.gwt.event.dom.client.ClickHandler;
import com.google.gwt.event.dom.client.ClickEvent;

import ecstore.client.dataOperation.ItemInfo;

public class ItemSlot extends Composite{
	DecoratorPanel decoratorPanel = new DecoratorPanel();
	VerticalPanel verticalPanel = new VerticalPanel();
	
	Image image = new Image();
	Label itemName = new Label("Pall Mall Amber 25");
	Label itemPriceTag = new Label("Price: $");
	
	/**
	 * @wbp.parser.constructor
	 */
	public ItemSlot() {
		decoratorPanel.setSize("56px", "85px");
		
		decoratorPanel.setWidget(verticalPanel);
		verticalPanel.setSize("59px", "84px");
		image.addClickHandler(new ClickHandler() {
			public void onClick(ClickEvent event) {
				ItemInfoPopup itemPop = new ItemInfoPopup();

			}
		});
		
		image.setUrl("http://www.tobacco.net.au/images/T/PALL_MALL_AMBER_25_TH.jpg");
		verticalPanel.add(image);
		
		itemName.setStyleName("gwt-LabelDescription");
		verticalPanel.add(itemName);
		
		itemPriceTag.setText("Price: $");		
		itemPriceTag.setStyleName("gwt-LabelDescription");
		verticalPanel.add(itemPriceTag);
		initWidget(decoratorPanel);
	}
	
	
	public ItemSlot(String imageURL, String name, String price){
		
		decoratorPanel.setSize("180px", "258px");
		
		decoratorPanel.setWidget(verticalPanel);
		verticalPanel.setSize("165px", "243px");
		
		image.setUrl(imageURL);
		verticalPanel.add(image);
		
		itemName.setStyleName("gwt-LabelDescription");
		verticalPanel.add(itemName);
		
		itemPriceTag.setText("Price: $");		
		itemPriceTag.setStyleName("gwt-LabelDescription");
		verticalPanel.add(itemPriceTag);
	
		initWidget(decoratorPanel);
		
	}
	
	public ItemSlot(final ItemInfo itemInfo) {
		decoratorPanel.setSize("56px", "85px");
		
		decoratorPanel.setWidget(verticalPanel);
		verticalPanel.setSize("59px", "84px");
		image.addClickHandler(new ClickHandler() {
			public void onClick(ClickEvent event) {
				ItemInfoPopup itemPop = new ItemInfoPopup(itemInfo);
//				itemPop.setImage(itemInfo.getImage());
//				itemPop.setTitle(itemInfo.getName());
//				System.out.println("pop up");
			}
		});
		
		image.setUrl(itemInfo.getThumbnail());
		verticalPanel.add(image);
		
		itemName.setStyleName("gwt-LabelDescription");
		itemName.setText(itemInfo.getName());
		verticalPanel.add(itemName);
		
		itemPriceTag.setStyleName("gwt-LabelDescription");
		itemPriceTag.setText("Price: $" + itemInfo.getPrice());
		verticalPanel.add(itemPriceTag);
		initWidget(decoratorPanel);
	}

	public void setSize(String x, String y){
		
	}
	
	public void setImage(String imageURL){
		image.setUrl(imageURL);
	}

	public void setName(String newName){
		itemName.setText(newName);
	}
	
	public void setPrice(float newPrice){
		itemPriceTag.setText("Price: $" + String.valueOf(newPrice));
	}
}
